package com.wgts.wgts.tools;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedpreferencesHelper {

    private SharedpreferencesHelper(){
    }

    private SharedPreferences sharedPreferences;

    private SharedPreferences.Editor editor;

    private static class SingletonHolder{
        private static final SharedpreferencesHelper _INSTANCE = new SharedpreferencesHelper();
    }

    public static SharedpreferencesHelper getInstance(){
        return SingletonHolder._INSTANCE;
    }

    public SharedpreferencesHelper init(Context context){
        applicationContext = context;

        sharedPreferences = applicationContext.getSharedPreferences("MoHuApp", Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
        return SingletonHolder._INSTANCE;
    }

    private Context applicationContext;


    public void write(String key, String value){
        editor.putString(key, value).commit();
    }

    public void write(String key, int value){
        editor.putInt(key, value).commit();
    }

    public void removeAll(){
        editor.clear().commit();
    }


    public String getString(String key){
        return sharedPreferences.getString(key, "");
    }

    public int getInt(String key){
        return sharedPreferences.getInt(key, 0);
    }


}
